package com.example.demo.control;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2017-6-9.
 */
@Controller
@RequestMapping
public class SessionUtil {

    static Logger logger = LoggerFactory.getLogger(SessionUtil.class);


    public static String gitname(HttpServletRequest request) {
        return getString("gitname", request);
    }


    public static String jenkinsname(HttpServletRequest request) {
        String s = getString("jenkinname", request);
        logger.info(s);

        return s;
    }

    public static String jp(HttpServletRequest request) {
        return getString("jenkinspwd", request);

    }

    public static String gp(HttpServletRequest request) {
        return getString("gitpwd", request);

    }

    private static String getString(String name, HttpServletRequest request) {
        for (Cookie cookie : request.getCookies()) {
            if (cookie.getName().equals(name)) {
                return cookie.getValue();
            }
        }

        return "";
    }


}
